import db from '../utils/dbconf'
import { SQL_ERROR } from '../server.config.js'
const TABLE_NAME = 'LOG'

export default{
  get:async ({query}, res) => {
    try{
      const { ciplike,actionlike,size,page } = query
      const wherefilter = { 
        cip   : ['LIKE',`%${ciplike   ||''}%`],
        action: ['LIKE',`%${actionlike||''}%`]
      }
    	const baseinfo = await db.table(TABLE_NAME)
        .where(wherefilter)
        .page(page,size)
        .select()
      const total = await db.table(TABLE_NAME)
        .where(wherefilter)
        .count('id')
      return res.send({
        code:200,
        data:{ baseinfo,total }
      })
    }catch(error){
    	return res.send(SQL_ERROR)
    }
  },
}